<!--Create: LT4-->
<!--Time:   2020年6月16日18:35:21-->
<!--Description:    显示物流具体信息-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>物流信息</title>
    <!--css-->
    <link rel="stylesheet" href="../../../static/css/bootstrap.min.css" th:href="@{../../../static/css/bootstrap.min.css}"></link>

</head>
<header>
    <nav class="navbar navbar-light bg-light navbar-expand">
        <a href="/" class="navbar-brand">Shop</a>
        <div class="collapse navbar-collapse">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a href="/" class="nav-link active">首页</a>
                </li>
                <form class="form-inline">
                    <input id="searchText" type="text" placeholder="Search" class="form-control"/>
                </form>
                <button id="search" class="btn btn-primary">搜索</button>
            </ul>
        </div>
        <div th:if="${#strings.isEmpty(session.user)}">
            <div class="btn-group">
                <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">登录</button>
                <div class="dropdown-menu dropdown-menu-right p-2 text-muted" style="width: 300px">
                    <form action="/userLogin" data-stopPropagation="true" method="post">
                        <div class="form-group">
                            <input type="hidden" id="path" name="path" value="/">
                        </div>
                        <div class="form-group" data-stop>
                            <label>用户名:</label>
                            <input id="username" name="username" type="text" class="form-control"
                                   placeholder="username">
                            <div id="noUsername" class="alert alert-danger alert-dismissible fade show"
                                 style="display:none">
                                <strong>用户名不能为空</strong>
                                <button id="noUserBtn" type="button" class="close">&times;</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>密码:</label>
                            <input id="password" name="password" type="password" class="form-control"
                                   placeholder="password">
                            <div id="noPassword" class="alert alert-danger alert-dismissible fade show"
                                 style="display:none">
                                <strong>请输入密码</strong>
                                <button id="noPwdBtn" type="button" class="close">&times;</button>
                            </div>
                        </div>
                        <div class="form-group" style="margin-top: 2px">
                            <button id="loginSubmit" type="submit" class="btn btn-primary" style="width: 100%;">登录
                            </button>
                            <span id="err" th:if="${not #strings.isEmpty(loginMsg)}">
                                    <div class="alert alert-danger alert-dismissible fade show">
                                        <strong th:text="${loginMsg}"></strong>
                                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                                    </div>
                                </span>
                        </div>
                        <div class="text-center">
                            <a href="/enroll">>前往注册</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div id="user" th:if="${session.user}">
            <img th:onclick="'javascript:locate(\''+'/user/'+${session.user.id}+'\')'"
                 style="height: 45px;width: 45px;margin-right: 20px"
                 class="rounded-circle dropdown-toggle" data-toggle="dropdown"
                 th:src="${session.user.iconURL!=null}?${session.iconPathPattern}+${session.user.iconURL}:@{/static/img/default.png}">
            <ul class="dropdown-menu dropdown-menu-right p-2 text-muted" role="menu" style="width: 100px">
                <a class="dropdown-item" href="/show/order/list">我的订单</a>
                <a class="dropdown-item"  href="/show/order/cart">我的购物车</a>
                <a th:if="${session.user.state==1}" class="dropdown-item"  href="/dashboard">管理</a>
                <a class="dropdown-item"  href="/logOut">登出</a>
            </ul>
            <span style="padding-right: 40px" th:text="${session.user.getUsername()}"></span>
        </div>

    </nav>

</header>
<br>
<main role="main">




    <div class="container">

        <div class="card">
            <h4 class="card-header">物流信息：</h4>
            <div class="card-body " style=" overflow-y:scroll; height:700px;">
                <div th:if="${expresslist}">
                    <div th:each="item : ${expresslist}">
                        <span class="card-title" th:text="${item.time}"></span><br>
                        <strong><span class="card-text" th:text="${item.context}"></span></strong><br><br>
                    </div>
                </div><br>
            </div>
            <div class="dropdown-divider"></div>
            <div class="card-body">
                <button type="button" class="btn btn-primary" style="float: right" th:if="${state} eq '2'" th:onclick="receiptGoods([[${id}]])">确认收货</button>
                <button type="button" class="btn btn-primary" style="float: right" th:if="${state} eq '3'" th:onclick="returnGoods([[${id}]])">退货</button>
            </div>
        </div>
    </div>


</main>


<body>

<script src="../../../static/js/jquery-3.3.1.js" th:src="@{../../../static/js/jquery-3.3.1.js}"></script>
<script src="../../../static/js/popper.min.js" th:src="@{../../../static/js/popper.min.js}"></script>
<script src="../../../static/js/bootstrap.min.js" th:src="@{../../../static/js/bootstrap.min.js}"></script>

<script type="text/javascript">
    window.onload=function () {
        console.log("ready");
    }
    $(function () {
        $(".dropdown-toggle").on("mouseover", function() {
            $(this).dropdown('toggle');
        })
    })
    function receiptGoods(id) {
        $.ajax({
            type:'put',
            dataType: 'json',
            contentType: 'application/json;charset=UTF-8',
            url:'http://localhost:8000/show/order/state',
            data:JSON.stringify({
                "id":id,
                "state":"3"
            }),
            success:function (data) {
                window.location.href="http://localhost:8000/"+data["locate"];
            },
            error:function (data) {
                console.log(data);
            }
        })
    }

    function returnGoods(id) {
        $.ajax({
            type:'put',
            dataType: 'json',
            contentType: 'application/json;charset=UTF-8',
            url:'http://localhost:8000/show/order/state',
            data:JSON.stringify({
                "id":id,
                "state":"4"
            }),
            success:function (data) {
                window.location.href="http://localhost:8000/"+data["locate"];
            },
            error:function (data) {
                console.log(data);
            }
        })
    }

    function locate(string)
    {
        window.open(string);
    }
</script>



</body>
</html>